pub mod sha256_intrinsics;
use std::time::Instant;
extern crate rand;
use rand::{thread_rng, Rng};
extern crate libc;
extern {
    fn sha256_process_x86(state:*mut [u32;8],data:*const [u8;64],length:u32);
}

#[deny(overflowing_literals)]
fn main() {
    test();
    // test1();
}

fn test(){
    let mut state: [u32; 8] = [
        0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
    ];
    let blocks:[u8;64]=[
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    ];
    let start = Instant::now();
    let a:u32=64;
    for i in 0..100_000_000 {
        unsafe { sha256_intrinsics::compress256(&mut state, &blocks,a) }
        unsafe { sha256_process_x86(&mut state, &blocks,a) }
    }
    println!("{:#?}",state);
    println!("test time cost1: {:?} us", start.elapsed().as_micros());
}
fn test1(){
    let mut state: [u32; 8] = [
        0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
    ];
    let start = Instant::now();
    let mut l=64;
    let blocks:[u8;64]=[
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    ];
    for i in 0..100_000 {

    }
    println!("time cost1: {:?} us", start.elapsed().as_micros());
}



